home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
tcl-mode.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-07-12
|
20KB
|
665 lines
;;; tcl-mode.el --- a major-mode for editing tcl/tk scripts
;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
;; Author: Gregor Schmid <schmid@fb3-s7.math.tu-berlin.de>
;; Keywords: languages, processes, tools
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Special Thanks to Simon Marshall <simonm@mail.esrin.esa.it> for
;; font-lock patches.
;; This file was written with emacs using Jamie Lokier's folding mode
;; That's what the funny ;;{{{ marks are there for
;;{{{ Usage
;; Tcl-mode supports c-mode style formatting and sending of
;; lines/regions/files to a tcl interpreter. An interpreter (see
;; variable `tcl-default-application') will be started if you try to
;; send some code and none is running. You can use the process-buffer
;; (named after the application you chose) as if it were an
;; interactive shell. See the documentation for `comint.el' for
;; details.
;;}}}
;;{{{ Key-bindings
;; To see all the keybindings for folding mode, look at `tcl-setup-keymap'
;; or start `tcl-mode' and type `\C-h m'.
;; The keybindings may seem strange, since I prefer to use them with
;; tcl-prefix-key set to nil, but since those keybindings are already used
;; the default for `tcl-prefix-key' is `\C-c', which is the conventional
;; prefix for major-mode commands.
;; You can customise the keybindings either by setting `tcl-prefix-key'
;; or by putting the following in your .emacs
;; (setq tcl-mode-map (make-sparse-keymap))
;; and
;; (define-key tcl-mode-map <your-key> <function>)
;; for all the functions you need.
;;}}}
;;{{{ Variables
;; You may want to customize the following variables:
;; tcl-indent-level
;; tcl-always-show
;; tcl-mode-map
;; tcl-prefix-key
;; tcl-mode-hook
;; tcl-default-application
;; tcl-default-command-switches
;;}}}
;;; Code:
;; We need that !
(require 'comint)
;;{{{ variables
(defvar tcl-default-application "wish"
"Default tcl/tk application to run in tcl subprocess.")
(defvar tcl-default-command-switches nil
"Command switches for `tcl-default-application'.
Should be a list of strings.")
(defvar tcl-process nil
"The active tcl subprocess corresponding to current buffer.")
(defvar tcl-process-buffer nil
"Buffer used for communication with tcl subprocess for current buffer.")
(defvar tcl-always-show t
"*Non-nil means display tcl-process-buffer after sending a command.")
(defvar tcl-mode-map nil
"Keymap used with tcl mode.")
(defvar tcl-prefix-key "\C-c"
"Prefix for all tcl-mode commands.")
(defvar tcl-mode-hook nil
"Hooks called when tcl mode fires up.")
(defvar tcl-region-start (make-marker)
"Start of special region for tcl communication.")
(defvar tcl-region-end (make-marker)
"End of special region for tcl communication.")
(defvar tcl-indent-level 4
"Amount by which tcl subexpressions are indented.")
(defvar tcl-default-eval "eval"
"Default command used when sending regions.")
(defvar tcl-mode-menu (make-sparse-keymap "Tcl-Mode")
"Keymap for tcl-mode's menu.")
(defvar tcl-font-lock-keywords
(eval-when-compile
(list
;;
;; Function name declarations.
'("\\<\\(itcl_class\\|method\\|proc\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
;;
;; Keywords.
;(make-regexp '("if" "then" "else" "elseif" "for" "foreach" "break"
; "continue" "while" "eval" "case" "in" "switch" "default"
; "exit" "error" "proc" "return" "uplevel" "constructor"
; "destructor" "itcl_class" "loop" "for_array_keys"
; "for_recursive_glob" "for_file"))
(concat "\\<\\("
"break\\|c\\(ase\\|on\\(structor\\|tinue\\)\\)\\|"
"de\\(fault\\|structor\\)\\|"
"e\\(lse\\(\\|if\\)\\|rror\\|val\\|xit\\)\\|"
"for\\(\\|_\\(array_keys\\|file\\|recursive_glob\\)\\|each\\)\\|"
"i\\([fn]\\|tcl_class\\)\\|loop\\|proc\\|return\\|switch\\|"
"then\\|uplevel\\|while"
"\\)\\>")
;;
;; Types.
; (make-regexp '("global" "upvar" "inherit" "public" "protected" "common"))
(cons (concat "\\<\\(common\\|global\\|inherit\\|"
"p\\(rotected\\|ublic\\)\\|upvar\\)\\>")
'font-lock-type-face)
))
"Default expressions to highlight in TCL modes.")
(defvar tcl-imenu-generic-expression
'((nil "^[ \t]*proc[ \t]+\\(\\(\\s_\\|\\sw\\)+\\)" 1))
"Imenu generic expression for tcl-mode. See `imenu-generic-expression'.")
;;}}}
;;{{{ tcl-mode
;;;###autoload
(defun tcl-mode ()
"Major mode for editing tcl scripts.
The following keys are bound:
\\{tcl-mode-map}
"
(interactive)
(let ((switches nil)
s)
(kill-all-local-variables)
(setq major-mode 'tcl-mode)
(setq mode-name "TCL")
(set (make-local-variable 'tcl-process) nil)
(set (make-local-variable 'tcl-process-buffer) nil)
(make-local-variable 'tcl-default-command-switches)
(set (make-local-variable 'indent-line-function) 'tcl-indent-line)
(set (make-local-variable 'comment-start) "# ")
(set (make-local-variable 'comment-start-skip) "# *")
(set (make-local-variable 'font-lock-defaults)
'(tcl-font-lock-keywords nil nil ((?_ . "w"))))
(set (make-local-variable 'imenu-generic-expression)
tcl-imenu-generic-expression)
(make-local-variable 'tcl-default-eval)
(or tcl-mode-map
(tcl-setup-keymap))
(use-local-map tcl-mode-map)
(set-syntax-table (copy-syntax-table))
(modify-syntax-entry ?# "<")
(modify-syntax-entry ?\n ">")
;; look for a #!.../wish -f line at bob
(save-excursion
(goto-char (point-min))
(if (looking-at "#![ \t]*\\([^ \t]*\\)[ \t]\\(.*[ \t]\\)-f")
(progn
(set (make-local-variable 'tcl-default-application)
(buffer-substring (match-beginning 1)
(match-end 1)))
(if (match-beginning 2)
(progn
(goto-char (match-beginning 2))
(set (make-local-variable 'tcl-default-command-switches) nil)
(while (< (point) (match-end 2))
(setq s (read (current-buffer)))
(if (<= (point) (match-end 2))
(setq tcl-default-command-switches
(append tcl-default-command-switches
(list (prin1-to-string s)))))))))
;; if this fails, look for the #!/bin/csh ... exec hack
(while (eq (following-char) ?#)
(forward-line 1))
(or (bobp)
(forward-char -1))
(if (eq (preceding-char) ?\\)
(progn
(forward-char 1)
(if (looking-at "exec[ \t]+\\([^ \t]*\\)[ \t]\\(.*[ \t]\\)*-f")
(progn
(set (make-local-variable 'tcl-default-application)
(buffer-substring (match-beginning 1)
(match-end 1)))
(if (match-beginning 2)
(progn
(goto-char (match-beginning 2))
(set (make-local-variable
'tcl-default-command-switches)
nil)
(while (< (point) (match-end 2))
(setq s (read (current-buffer)))
(if (<= (point) (match-end 2))
(setq tcl-default-command-switches
(append tcl-default-command-switches
(list (prin1-to-string s)))))))))
)))))
(run-hooks 'tcl-mode-hook)))
;;}}}
;;{{{ tcl-setup-keymap
(defun tcl-setup-keymap ()
"Set up keymap for tcl mode.
If the variable `tcl-prefix-key' is nil, the bindings go directly
to `tcl-mode-map', otherwise they are prefixed with `tcl-prefix-key'."
(setq tcl-mode-map (make-sparse-keym